/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.ifrn.Dao;

import br.edu.ifrn.Classes.Conexao;
import br.edu.ifrn.Classes.Solicitacao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Edmilson
 */
public class SolicitacaoDao {
    private Connection connection;

    public SolicitacaoDao() {
        this.connection = new Conexao().getConnection();
    }
    
    public void JulgarSolicitacao(Solicitacao solicitacao){
        String sql = "UPDATE solicitacao SET status=? WHERE idSolicitacao=?";
        
        try{
            java.sql.PreparedStatement stmt = this.connection.prepareStatement(sql);
            stmt.setString(1, solicitacao.getStatus());
            stmt.setInt(2, solicitacao.getIdSolicitacao());
            
            stmt.execute();
            stmt.close();
        }catch(SQLException e){
            throw new RuntimeException(e);            
        }
    }
    
    public List<Solicitacao> ListarSolicitacoes() {
        try {
            List<Solicitacao> solicitacoes = new ArrayList<Solicitacao>();
            PreparedStatement stmt = this.connection.prepareStatement("select * from solicitacao");
            ResultSet rs = stmt.executeQuery();

            while (rs.next()) {
                // criando o objeto Contato
                Solicitacao solicitacao = new Solicitacao();
                solicitacao.setIdSolicitacao(rs.getInt("idSolicitacao"));
                solicitacao.setIdPessoa(rs.getInt("idPessoa"));
                solicitacao.setIdTipoSolicitacao(rs.getInt("idTipoSolicitacao"));
                solicitacao.setQtdCopias(rs.getInt("qtdCopias"));
                solicitacao.setQtdFolhasMatriz(rs.getInt("qtdFolhasMatriz"));
                solicitacao.setStatus(rs.getString("status"));

                // adicionando o objeto à lista
                solicitacoes.add(solicitacao);
            }
            rs.close();
            stmt.close();
            return solicitacoes;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }    
}
